import { request } from '../utils/request';
import type { ApiResponse, Workspace, WorkspaceMember, User } from '../types/api';

export const workspaceAPI = {
  // 创建工作区
  createWorkspace: (data: { name: string; description?: string }) => {
    return request.post<ApiResponse<Workspace>>('/workspaces', data);
  },

  // 获取所有工作区
  getWorkspaces: () => {
    return request.get<ApiResponse<Workspace[]>>('/workspaces');
  },

  // 获取我的工作区
  getMyWorkspaces: () => {
    return request.get<ApiResponse<Workspace[]>>('/workspaces/my');
  },

  // 获取工作区详情
  getWorkspace: (id: string) => {
    return request.get<ApiResponse<Workspace>>(`/workspaces/${id}`);
  },

  // 更新工作区
  updateWorkspace: (id: string, data: { name?: string; description?: string }) => {
    return request.put<ApiResponse<Workspace>>(`/workspaces/${id}`, data);
  },

  // 删除工作区（软删除）
  deleteWorkspace: (id: string) => {
    return request.delete<ApiResponse<void>>(`/workspaces/${id}`);
  },

  // 永久删除工作区
  permanentDeleteWorkspace: (id: string) => {
    return request.delete<ApiResponse<void>>(`/workspaces/${id}/permanent`);
  },

  // 获取工作区成员
  getWorkspaceMembers: (workspaceId: string) => {
    return request.get<ApiResponse<WorkspaceMember[]>>(`/workspaces/${workspaceId}/members`);
  },

  // 添加工作区成员
  addWorkspaceMember: (workspaceId: string, data: { userId: string; roleId: string }) => {
    return request.post<ApiResponse<WorkspaceMember>>(`/workspaces/${workspaceId}/members`, data);
  },

  // 更新工作区成员
  updateWorkspaceMember: (workspaceId: string, memberId: string, data: { roleId: string }) => {
    return request.put<ApiResponse<WorkspaceMember>>(`/workspaces/${workspaceId}/members/${memberId}`, data);
  },

  // 移除工作区成员
  removeWorkspaceMember: (workspaceId: string, memberId: string) => {
    return request.delete<ApiResponse<void>>(`/workspaces/${workspaceId}/members/${memberId}`);
  },

  // 获取可添加的用户列表
  getAvailableUsers: (workspaceId: string) => {
    return request.get<ApiResponse<User[]>>(`/workspaces/${workspaceId}/available-users`);
  },
}; 